package com.freework.sys.dic.vo;

import com.freework.freedbm.dao.jdbcm.JdbcForDTO;
import com.freework.freedbm.dao.jdbcm.map.dto.MapDTO;
public class DicVO extends MapDTO {
	public final static int ID_INDEX = 0;
	public final static int CODE_INDEX = 1;
	public final static int NAME_INDEX = 2;
	private transient JdbcForDTO[]  updateFieldIndexs=null;

	private int updateFieldIndexsSize=0;
	public DicVO(DICVOCfg cfg) {
		super(cfg);
		updateFieldIndexs=new JdbcForDTO[cfg.getFields().length];
	}
	public Object getId() {
		return this.getIndex(ID_INDEX);
	}

	public Object getName() {
		return (String) this.getIndex(NAME_INDEX);
	}

	public Object getCode() {
		return (String) this.getIndex(CODE_INDEX);
	}

	public Object put(String key, Object value) {
		Integer index=	keysIndex.getIndex(key);
		if(index!=null){
			
			Object oldobj= values[index];
			values[index]=value;
			addUpdateField(index);
			this.index++;
			return oldobj;
		}else{
			return null;
		}
	}

	public void putIndex(int index, Object value) {
		if(values.length>index){
			values[index]=value;
			addUpdateField(index);

		}
		//return value;
	}
	
	protected void addUpdateField(int index){
		DICVOCfg cfg=(DICVOCfg)this.keysIndex;
		if(updateFieldIndexs[index]==null){
		updateFieldIndexs[index]=cfg.getFields()[index];
		updateFieldIndexsSize++;
		}
	}
	public  JdbcForDTO[] updateField(){
		JdbcForDTO fieldInfos[]=new JdbcForDTO[updateFieldIndexsSize];
		int i=0;
		for (int j=0;j< updateFieldIndexs.length;j++) {
			JdbcForDTO fieldInfo2 =updateFieldIndexs[j];
			if(fieldInfo2!=null){
				fieldInfos[i]=fieldInfo2;
				i++;
				if(i==updateFieldIndexsSize)
					break;
			}
			
		}
		
			return fieldInfos;
	
	}
}
